<template>
  <div>
    <product-param :title="product.name"></product-param>
    <div class="wrapper container">
      <div class="swiper">
        <swiper :options="swiperOptions">
          <swiper-slide
            ><img src="/imgs/detail/phone-1.jpg" alt=""
          /></swiper-slide>
          <swiper-slide
            ><img src="/imgs/detail/phone-2.jpg" alt=""
          /></swiper-slide>
          <swiper-slide
            ><img src="/imgs/detail/phone-3.jpg" alt=""
          /></swiper-slid09e>
          <swiper-slide
            ><img src="/imgs/detail/phone-4.jpg" alt=""
          /></swiper-slide>
          <!-- Optional controls -->
          <div class="swiper-pagination" slot="pagination"></div>
        </swiper>
      </div>
      <div class="content">
        <h2 class="item-title">{{product.name}}</h2>
        <p class="item-info">
          相机全新升级 / 960帧超慢动作 / 手持超级夜景 / 全球首款双频GPS /
          骁龙845处理器 / 红<br />外人脸解锁 / AI变焦双摄 / 三星 AMOLED 屏
        </p>
        <div class="delivery">小米自营</div>
        <div class="item-price">
          <span>{{product.price}}元</span>
          <span class="del">1999元</span>
        </div>
        <div class="item-addr">
          <i class="icon-loc"></i>
          <div class="addr">北京 北京市 朝阳区 安定门街道</div>
          <div class="stock">有现货</div>
        </div>
        <h2 class="choose-version">选择版本</h2>
        <div class="item-version">
          <div
            class="phone"
            :class="{ checked: version }"
            @click="chooseVersion"
          >
            6GB+64GB 全网通
          </div>
          <div
            class="phone"
            :class="{ checked: !version }"
            @click="chooseVersion"
          >
            4GB+64GB 移动4G
          </div>
        </div>
        <h2 class="choose-color">选择颜色</h2>
        <div class="item-color">
          <div class="phone checked">
            <span class="color"></span>
            深空灰
          </div>
        </div>
        <div class="item-total">
          <div class="phone-info clearfix">
            <div class="pro-info">{{product.name}} {{version?'6GB+64GB 全网通':'4GB+64GB 移动4G'}} 深灰色</div>
            <div class="pro-pri">{{product.price}}元</div>
          </div>
          <div class="phone-total">总计：{{product.price}}元</div>
        </div>
        <div class="btn-group">
          <a href="javascript:;" class="btn btn-huge" @click="addCart"
            >加入购物车</a
          >
        </div>
      </div>
    </div>
    <div class="price-info">
      <div class="container">
        <h2>价格说明</h2>
        <div class="desc">
          <img src="/imgs/detail/item-price.jpeg" alt="" />
        </div>
      </div>
    </div>
    <ServiceBar />
  </div>
</template>

<script>
import ProductParam from "@/components/ProductParam";
import ServiceBar from "@/components/ServiceBar";
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/dist/css/swiper.css";
export default {
  name: "product",
  components: {
    ProductParam,
    Swiper,
    SwiperSlide,
    ServiceBar,
  },
  data() {
    return {
      swiperOptions: {
        autoplay: true,
        pagination: {
          el: ".swiper-pagination",
          clickable: true,
        },
      },
      version: true,
      product:{}
    };
  },
  mounted() {
    this.getProductInfo();
  },
  methods: {
    chooseVersion() {
      this.version = !this.version;
    },
    addCart() {
      const productId = this.$route.params.id;
      this.axios.post('/carts',{
          productId,
          selected: true
      }).then((res={cartProductVoList:0})=>{
        this.$store.dispatch('saveCartCount',res.cartTotalQuantity)
      })
    },
    getProductInfo() {
      const id = this.$route.params.id;
      this.axios.get(`/products/${id}`).then((res) => {
        this.product = res
      });
    },
  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/scss/config.scss";
@import "@/assets/scss/mixin.scss";
@import "@/assets/scss/button.scss";
.wrapper {
  display: flex;
  .swiper {
    width: 642px;
    height: 617px;
    margin-top: 5px;
    img {
      width: 100%;
      height: 100%;
    }
  }

  .content {
    .item-title {
      font-size: 28px;
      padding-top: 30px;
      padding-bottom: 16px;
    }
    .item-info {
      font-size: 14px;
      height: 36px;
    }
    .delivery {
      font-size: 16px;
      color: #ff6700;
      margin-top: 26px;
      margin-bottom: 14px;
      height: 15px;
    }
    .item-price {
      font-size: 20px;
      color: #ff6700;
      padding-bottom: 25px;
      border-bottom: 1px solid #e5e5e5;
      margin-bottom: 28px;
      .del {
        font-size: 16px;
        color: #999999;
        margin-left: 10px;
        text-decoration: line-through;
      }
    }
    .item-addr {
      height: 108px;
      background-color: #fafafa;
      border: 1px solid #e5e5e5;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      padding-top: 31px;
      padding-left: 64px;
      font-size: 14px;
      line-height: 14px;
      position: relative;
      .icon-loc {
        position: absolute;
        top: 27px;
        left: 34px;
        display: inline-block;
        width: 20px;
        height: 20px;
        background: url(/imgs/detail/icon-loc.png) no-repeat center;
        background-size: contain;
      }
      .addr {
        color: #666666;
      }
      .stock {
        margin-top: 15px;
        color: #ff6700;
      }
    }
    .choose-color {
      margin-top: 30px;
      font-size: 18px;
      margin-bottom: 20px;
    }
    .choose-version {
      margin-top: 30px;
      font-size: 18px;
      margin-bottom: 20px;
    }
    .item-version {
      display: flex;
    }
    .phone {
      margin-right: 5px;
      border: 1px solid #e5e5e5;
      width: 287px;
      height: 50px;
      line-height: 50px;
      text-align: center;
      cursor: pointer;
      font-size: 16px;
      &.checked {
        border: 1px solid #ff6600;
        color: #ff6600;
      }
    }
    .item-total {
      background: #fafafa;
      padding: 24px 33px 29px 30px;
      margin-top: 50px;
      margin-bottom: 30px;
      font-size: 14px;
      .phone-info {
        @include flex();
      }
      .phone-total {
        font-size: 24px;
        color: #ff6600;
        margin-top: 18px;
      }
    }
  }
}
.price-info {
  background-color: #f3f3f3 !important;
  height: 340px;
  margin-top: 50px;
  h2 {
    font-size: 24px;
    color: #333333;
    padding-top: 38px;
    margin-bottom: 30px;
  }
}
</style>